const proto = {};
class Delegate {
  constructor(target, property) {
    this.target = target;
    this.property = property; // request | response
  }
  getter(key) {
    // ctx.query
    let that = this;
    this.target.__defineGetter__(key, function () {
      return this[that.property][key];
    });
    return this;
  }
  setter(key) {
    // ctx.query
    let that = this;
    this.target.__defineSetter__(key, function (val) {
      this[that.property][key] = val;
    });
    return this;
  }
  access(key) {
    return this.getter(key).setter(key);
  }
}
function delegate(target, property) {
  return new Delegate(target, property);
}

delegate(proto, "request").access("path").access("query").access("url");
// Object.defineProperty / proxy  代理分为设置和获取，都需要配置
delegate(proto, "response").access("body");
// __defineGetter__
module.exports = proto;
